/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    CWI Amsterdam - initial API and implementation
 */
package nl.cwi.arne.mcrl2.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import nl.cwi.arne.mcrl2.Specification;

/**
 * @author Christian Krause
 * @generated NOT
 */
public class MCRL2FileUtil {

	public static File[] createTmpFiles(String... extensions) throws IOException {
		File[] files = new File[extensions.length];
		for (int i=0; i<extensions.length; i++) {
			files[i] = File.createTempFile("tmp", "." + extensions[i]);
		}
		return files;
	}

	/**
	 * Save a mCRL2 specification to a temporary *.mcrl2 file.
	 */
	public static File saveSpecification(Specification specification) {
		try {
			File mcrl2File = File.createTempFile("tmp", ".mcrl2");
			FileWriter writer = new FileWriter(mcrl2File);
			writer.write(specification.toString());
			writer.close();
			return mcrl2File;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * Save the the formula to a file.
	 */
	public static File saveFormula(String formula) {
		try {
			File mcfFile = File.createTempFile("tmp", ".mcf");
			FileWriter writer = new FileWriter(mcfFile);
			writer.write(formula + "\n");
			writer.close();
			return mcfFile;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

}
